package com.mini.gateway.core.modules.route.dto;

import com.mini.gateway.core.modules.route.entity.MiniRoute;
import com.mini.gateway.core.modules.route.enums.RouteType;
import lombok.Data;
import org.springframework.cloud.gateway.filter.FilterDefinition;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * RouteDefined
 *
 */
@Data
public class RouteDefined {

    private Integer id;
    private String path;
    private RouteType type;
    private String name;
    private String uri;
    private Integer orders;
    private List<FilterDefinition> filterList = new ArrayList<>();

    public RouteDefined() {}

    public RouteDefined(MiniRoute route) {
        this.id = route.getId();
        this.path = route.getPath();
        this.type = route.getType();
        this.name = route.getName();
        this.uri = route.getUri();
        this.orders = route.getOrders();
    }

    public void addFilter(String name, Map<String, String> args) {
        FilterDefinition filter = new FilterDefinition();
        filter.setName(name);
        filter.setArgs(args);
        filterList.add(filter);
    }

}
